package com.system.controller.sysuser;

import com.common.core.constants.HttpConstants;
import com.common.core.controller.BaseController;
import com.common.core.domain.Result;
import com.common.core.domain.vo.LoginUserVO;
import com.system.domain.sysuser.dto.LoginDTO;
import com.system.domain.sysuser.dto.SysUserSaveDTO;
import com.system.service.sysuser.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员API")
public class SysUserController extends BaseController {
    @Resource
    SysUserService service;

    /**
     *登录
     *
     */
    @PostMapping("/login")
    @Operation(summary = "管理员登录",description = "根据账号和密码登录管理员账号")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "账号或密码错误")
    public Result<String> login(@RequestBody LoginDTO loginDTO){
        return service.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }

    /**
     *数据预置
     *
     */
    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toResult(service.add(sysUserSaveDTO));
    }

    /**
     *获取用户信息
     *
     */
    @GetMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return service.info(token);
    }

    /**
     *退出登录
     *
     */
    @DeleteMapping("/logout")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult(service.logout(token));
    }

    /**
     *演示作用
     *
     */
    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "用户ID")
    })
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public Result<Void> delete(@PathVariable Long userId) {
        System.out.println("进入删除用户delete");
        return null;
    }
    /**
     *测试功能
     *
     */
    @RequestMapping("/test")
    public String test(){
        //http://127.0.0.1:19090/system/test
        return "验证成功";
    }
}
